﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using mscook.core;
using mscook.core.components;
using mscook.mvc.Controllers;

namespace mscook.mvc.Core
{
    public class ResourceBonusFilter : ActionFilterAttribute
    {
        public string resourceId { get; set; }
        ResourceBonusStrategy resourceBonusStrategy;
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            resourceId = filterContext.ActionParameters["id"].ToString();//2013-11-26 action中的参数
            var thisController = ((BaseController)filterContext.Controller);  
            if(string.IsNullOrEmpty(resourceId))
                filterContext.Result = new RedirectToRouteResult(new System.Web.Routing.RouteValueDictionary(new { Controller = "Error", action = "Index" }));   
            resourceBonusStrategy = new ResourceBonusStrategy(resourceId,thisController.ResourceBonusSettings, thisController.CurrentUser, thisController.LoginUserService);
            if (!resourceBonusStrategy.HashRight())
                filterContext.Result = new RedirectToRouteResult(new System.Web.Routing.RouteValueDictionary(new { Controller = "Home", action = "Index" }));
        }
    


    }
}